package X4;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class JobMain extends Configured implements Tool {
    @Override
    public int run(String[] strings) throws Exception {
        //创建job任务对象
        Job job=Job.getInstance(super.getConf(),"wordCount");
        //配置job对象（8个步骤）
        //读取
        job.setInputFormatClass(TextInputFormat.class);//读取方式
        TextInputFormat.addInputPath(job,new Path("hdfs://192.168.43.171:9000/data/word.data"));//源文件名称
        //map
        job.setMapperClass(WordCountMapper.class);//map处理方式
        job.setOutputKeyClass(Text.class);//map-k2类型
        job.setMapOutputValueClass(LongWritable.class);//map-v2类型
        //
        //reduce
        job.setReducerClass(WordConutReducer.class);//r处理方式
        job.setOutputKeyClass(Text.class);//r-k3类型
        job.setOutputValueClass(LongWritable.class);//r-v3类型
        //输出类型
        job.setCombinerClass(WordCoundCombiner.class);

        job.setOutputFormatClass(TextOutputFormat.class);//读取方式
        TextOutputFormat.setOutputPath(job,new Path("hdfs://192.168.43.171:9000/data/word.7"));//输出路径

        //等待结束
        boolean b1=job.waitForCompletion(true);
        return b1 ? 0:1;
    }

    public static void main(String[] args) throws Exception {
        Configuration configuration=new Configuration();
        //启动脚步任务
        int run=ToolRunner.run(configuration,new JobMain(),args);
        System.exit(run);
    }
}
